package com.utils;

import com.thoughtworks.xstream.XStream;

/**
 * @author zhangyan
 * @version $ Id: XmlUtil.java, v 0.1 2021/11/19 17:40 zhangyan Exp $
 */
public class XmlUtil {

    /**
     * xml字符串转对象
     *
     * @param clazz 对象类型
     * @param xml   xml字符串
     * @return 对象
     */
    public static<T> T toObj(Class<T> clazz, String xml) {
        XStream xStream = new XStream();
        xStream.processAnnotations(clazz);
        xStream.autodetectAnnotations(true);
        Object o = xStream.fromXML(xml);
        T t = (T) o;
        return t;
    }
}
